// ***************************************************************
//  SPopTip   version:  1.0    date:  2008-05-04
//  -------------------------------------------------------------
//  Author: Soli (soli163@163.com)
//  
//  -------------------------------------------------------------
//  Copyright (C) 2008 - All Rights Reserved
// ***************************************************************
// 
// ***************************************************************
#if !defined(AFX_SPOPTIP_H__3B76F960_ECA5_4726_9417_621C6A94AFF4__INCLUDED_)
#define AFX_SPOPTIP_H__3B76F960_ECA5_4726_9417_621C6A94AFF4__INCLUDED_

#include "PPHtmlDrawer.h"	// Added by ClassView
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// SPopTip.h : header file
//
#include "PPHtmlDrawer.h"

//Tip's directions
#define PPTOOLTIP_TOPEDGE_LEFT			0x00
#define PPTOOLTIP_TOPEDGE_RIGHT			0x01
#define PPTOOLTIP_TOPEDGE_CENTER		0x02
#define PPTOOLTIP_BOTTOMEDGE_LEFT		0x10
#define PPTOOLTIP_BOTTOMEDGE_RIGHT		0x11
#define PPTOOLTIP_BOTTOMEDGE_CENTER		0x12
#define PPTOOLTIP_LEFTEDGE_TOP			0x20
#define PPTOOLTIP_LEFTEDGE_BOTTOM		0x21
#define PPTOOLTIP_LEFTEDGE_VCENTER		0x22
#define PPTOOLTIP_RIGHTEDGE_TOP			0x30
#define PPTOOLTIP_RIGHTEDGE_BOTTOM		0x31
#define PPTOOLTIP_RIGHTEDGE_VCENTER		0x32

#define UDM_TOOLTIP_REPAINT		   (WM_USER + 100)

#define PPTOOLTIP_CLASSNAME    _T("CSPopTip")  // Window class name

/////////////////////////////////////////////////////////////////////////////
// CSPopTip window

class CSPopTip : public CWnd
{
// Construction
public:
	CSPopTip();
	virtual ~CSPopTip();

	BOOL Create(CWnd* pParentWnd, BOOL bBalloon = TRUE);

// Attributes
public:
	enum {	PPTTSZ_ROUNDED_CX = 0,
		PPTTSZ_ROUNDED_CY,
		PPTTSZ_MARGIN_CX,
		PPTTSZ_MARGIN_CY,
		PPTTSZ_WIDTH_ANCHOR,
		PPTTSZ_HEIGHT_ANCHOR,
		PPTTSZ_MARGIN_ANCHOR,
		PPTTSZ_OFFSET_ANCHOR_CX,
		PPTTSZ_OFFSET_ANCHOR_CY,
		
		PPTTSZ_MAX_SIZES
		};

protected:
	HWND m_hParentWnd; // The handle of the parent window

	CString m_strTip;
	CPPHtmlDrawer m_HtmlDrawer;

	POINT m_posTip;
	CRect m_rcTipArea; //The bound rect around the tip's area in the client coordinates.
	CRect m_rcTip; //The bound rect around the body of the tip in the client coordinates.
	CRect m_rcBoundsTip; //The bound rect around a tip include an anchor

	int  m_nSizes [PPTTSZ_MAX_SIZES]; //All sizes 

	// Info about current tool
	//CRect m_rcCurTool;
	DWORD m_dwDirection;
	BYTE  m_nTransparency;

	HRGN m_hrgnTip;

	//Background
	HBITMAP m_hBitmapBk; //A bitmap with tip's background only
	HBITMAP m_hUnderTipBk;

	DWORD m_dwEffectBk;
	BYTE  m_nGranularity;

	//Colors
	COLORREF m_clrBeginBk;
	COLORREF m_clrMidBk;
	COLORREF m_clrEndBk;

	//Shadow of the tip
	BOOL m_bGradientShadow;
	SIZE m_szOffsetShadow;
	SIZE m_szDepthShadow;
	BYTE m_nDarkenShadow;

	//Border of the tooltip
	HBRUSH m_hbrBorder;
	SIZE m_szBorder;

	BOOL m_bHyperlinkEnabled;

// Operations
public:
	void Show(LPPOINT pt, LPCTSTR lpszString, HICON hIcon = NULL);
	void UpdateTipText(LPCTSTR lpszText, HICON hIcon = NULL);
	void Hide();

	//functions for sizes
	void SetSize(int nSizeIndex, int nValue);
	int GetSize(int nSizeIndex);
	void SetDefaultSizes(BOOL bBalloonSize = TRUE);
	void SetMaxTipWidth(int nWidth = 0);

	//functions for direction
	void SetDirection (DWORD dwDirection = PPTOOLTIP_BOTTOMEDGE_LEFT);
	DWORD GetDirection();

	//Shadow of the tooltip
	void SetTipShadow(int nOffsetX, int nOffsetY, BYTE nDarkenPercent = 50, BOOL bGradient = TRUE, int nDepthX = 7, int nDepthY = 7);
	void SetImageShadow(int nOffsetX, int nOffsetY, BYTE nDarkenPercent = 50, BOOL bGradient = TRUE, int nDepthX = 7, int nDepthY = 7);

	void SetBorder(COLORREF color, int nWidth = 1, int nHeight = 1);
	void SetBorder(HBRUSH hbr, int nWidth = 1, int nHeight = 1);
	void HideBorder();

	// color's functions
	void SetColorBk(COLORREF color);
	void SetColorBk(COLORREF clrBegin, COLORREF clrEnd);
	void SetColorBk(COLORREF clrBegin, COLORREF clrMid, COLORREF clrEnd);
	void SetEffectBk(DWORD dwEffect, BYTE nGranularity = 5);

	void EnableHyperlink(BOOL bEnable = TRUE);

protected:
	void PrepareDisplayTip(LPPOINT lpPoint);
	void OnRedrawTip(HDC hDC, BYTE nTransparency = 0);
	virtual void OnDrawBorder(HDC hDC, HRGN hRgn);

	DWORD GetTipDirection(DWORD dwDirection, const CPoint & ptPoint, CPoint & ptAnchor, CRect & rcBody, CRect & rcFull, CRect & rcTipArea);
	HRGN GetTipRgn(DWORD dwDirection, int x, int y, int nWidth, int nHeight);
	void FreeResources();

// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CSPopTip)
	//}}AFX_VIRTUAL

// Implementation
public:

	// Generated message map functions
protected:
	//{{AFX_MSG(CSPopTip)
	afx_msg void OnPaint();
	//}}AFX_MSG
	afx_msg LRESULT OnRepaintWindow(WPARAM wParam, LPARAM lParam);
	DECLARE_MESSAGE_MAP()
};

/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_SPOPTIP_H__3B76F960_ECA5_4726_9417_621C6A94AFF4__INCLUDED_)
